package model.humanbody;

import static org.junit.Assert.*
import model.agent.AgentInterface
import model.agent.AgentVariable
import model.agent.AgentVariableInterface

import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test


//@CompileStatic
class HumanBodyTest2 {

	final shouldFail = new GroovyTestCase().&shouldFail

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		HumanBody body = new HumanBody()

		//==============body的属性系列开始===========
		body.addVariable(new AgentVariable("气虚"))
		body.addVariable(new AgentVariable("气郁"))
		//body.addProperty(new AgentProperty("血虚"))

		assert(body.getCondition("气虚") == 0)
		
		int x =  body.气虚
		assert(body.气虚 == 0)

		body.setCondition("气虚", 1)

		assert(body.getCondition("气虚") == 1)
		assert(body.气虚 == 1)

		body.气虚 --
		assert(body.气虚 == 0)

		//使用引号是可以的
		assert body."气虚" == 0

		//不存在的属性
		shouldFail(Exception){ body.getCondition("血虚") }
		shouldFail(Exception){
			body.setCondition("血虚",1)
		}
		shouldFail(Exception){ body.血虚 = 1 }
		//==============body的属性系列结束===========


		//==============body的子主体系列结束===========
		def o = new Organ("心")

		o.addVariable(new AgentVariable("心气虚"))
		o.addVariable(new AgentVariable("心血虚"))
		//o.addProperty(new AgentProperty("心阴虚"))

		body.addOrgan(o)

		assert(body.getCondition("心气虚") == 0)
		assert(body.心气虚 == 0)

		body.setCondition("心气虚",1)
		assert(body.getCondition("心气虚") == 1)

		body.心气虚 --
		assert(body.心气虚 == 0)

		// 用来做条件判断，只能判断0：false和非0:true
		body.心气虚 = 0
		if(body.心气虚){
			assert(false)
		}

		body.心气虚 = 1

		if(body.心气虚){
			assert(true)
		}

		if(!body.心气虚){
			assert(false)
		}

		
		//不存在的属性
		shouldFail(Exception){ body.getCondition("心阴虚") }
		shouldFail(Exception){
			body.setCondition("心阴虚",1)
		}
		//shouldFail(Exception){ body.心阴虚 = 1 }
		
		AgentInterface a = body.searchVariableOnAgent("心气虚")
		AgentVariableInterface v = a.variables["心气虚"]
		
		a.setVarTimestamp("心气虚",1)
		assert(a.getVarTimestamp("心气虚") == 1)
		
		AgentVariableInterface vv = body.searchVariable("心气虚")
		assert(vv.value == 1)
		

	}

}
